﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wolfbyte.Core.Repositories;
using System.Web;

namespace Wolfbyte.Core.UnitOfWork
{
    public class UnitOfWorkApplicationRepository<T> : IRepository<T>
        where T : class
    {
        private IRepository<T> Repository
        {
            get
            {
                var Application = UnitOfWorkApplication.CurrentApplication;
                if (Application == null)
                    throw new InvalidOperationException("Current Application is not a UnitOfWorkApplication");
                return Application.CurrentUnitOfWork.Repository<T>();
            }
        }

        #region IRepository<T> Members

        public IQueryable<T> Items
        {
            get { return Repository.Items; }
        }

        public void Add(T newItem)
        {
            Repository.Add(newItem);
        }

        #endregion
    }
}
